#include "../mqserver/mq_exchange.hpp"
#include <gtest/gtest.h>
using namespace wzf;

std::shared_ptr<wzf::ExchangeManager> emp;

class ExchangeTest:public testing::Environment
{
public:
    virtual void SetUp() override
    {
        emp = std::make_shared<wzf::ExchangeManager>("./data/test.db");
    }
    virtual void TearDown() override
    {
        // emp->Clear();
        DLOG("clear");
    }
};
// TEST(exchange_test, insert_test)
// {
//     std::unordered_map<std::string, std::string> mp {{"key1", "val1"}};
//     emp->DeclareExchange("exchange1", wzf::ExchangeType::DIRECT, DeliveryMode::DURABLE, false, mp);
//     emp->DeclareExchange("exchange2", wzf::ExchangeType::DIRECT, DeliveryMode::DURABLE, false, mp);
//     emp->DeclareExchange("exchange3", wzf::ExchangeType::DIRECT, DeliveryMode::DURABLE, false, mp);
//     emp->DeclareExchange("exchange4", wzf::ExchangeType::DIRECT, DeliveryMode::DURABLE, false, std::unordered_map<std::string, std::string>());
//     ASSERT_EQ(emp->Size(), 4);
// } 
TEST(exchange_test, select_test)
{   
    std::shared_ptr<Exchange> exp = emp->SelectExchange("exchange1");
    ASSERT_EQ(exp->name, "exchange1");
    ASSERT_EQ(exp->type, ExchangeType::DIRECT);
    ASSERT_EQ(exp->durable, DeliveryMode::DURABLE);
    ASSERT_EQ(exp->auto_delete, false);
    ASSERT_EQ(exp->GetArgs(), "key1=val1&");
}
TEST(exchange_test, remove_test)
{   
    emp->DeleteExchange("exchange3");
    ASSERT_NE(emp->Exists("exchange3"), true); 

    std::shared_ptr<Exchange> exp = emp->SelectExchange("exchange1");
    ASSERT_EQ(exp->name, "exchange1");
    ASSERT_EQ(exp->type, ExchangeType::DIRECT);
    ASSERT_EQ(exp->durable, DeliveryMode::DURABLE);
    ASSERT_EQ(exp->auto_delete, false);
    ASSERT_EQ(exp->GetArgs(), "key1=val1&");
}
int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    int ret = RUN_ALL_TESTS();
    return 0;
} 